from django.db import models

# Create your models here.

# 班级表
class Classes(models.Model):
    # verbose_name admin 显示字段
    # null=True 数据库允许为空  blank=True 前端传入数据 允许为空
    # TextField 文本类型
    name = models.CharField(max_length=20, unique=True,verbose_name="班级名称")
    slogan = models.TextField(null=True,blank=True,verbose_name="班级口号")
    create_time = models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True,verbose_name="修改时间")
    # 逻辑删除  is_delete == False / True
    is_delete = models.BooleanField(default=False,verbose_name="逻辑删除")



    class Meta:
        db_table = 'classes'

    def delete(self):
        # 修改
        self.is_delete = True
        self.save()

    def __str__(self):
        return self.name

class Student(models.Model):
    SEX_CHOICES = ((0,"女"),(1,"男"))
    name = models.CharField(max_length=20, unique=True,verbose_name="学生姓名")
    age = models.IntegerField(null=True,blank=True,verbose_name="年龄")
    sex = models.IntegerField(null=True,blank=True,verbose_name="性别",choices=SEX_CHOICES)
    create_time = models.DateTimeField(auto_now_add=True,verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True,verbose_name="修改时间")
    # 逻辑删除  is_delete == False / True
    is_delete = models.BooleanField(default=False,verbose_name="逻辑删除")
    classes = models.ForeignKey(Classes,null=True,on_delete=models.SET_NULL)

    class Meta:
        db_table = 'student'


    def delete(self):
        # 修改
        self.is_delete = True
        self.save()
























